package com.ranshiyan.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ranshiyan.entity.Article;
import com.ranshiyan.entity.Comment;

public interface ArticleMapper {
	
	List<Article> list();
	
	Article getById(int id);
	
	//添加评论
	@Insert("INSERT INTO cms_comment(articleId,userId,content,created) "+ "VALUES(#{articleId},#{userId},#{content},now())")
	int addComment(Comment comment);
	
	//如果添加评论成功则添加评论的评论数量
	@Update("UPDATE cms_article SET commentCnt=commentCnt+1 WHERE id=#{value}")
	void increaseCommentCnt(int id);
	
	//根据文章id列出来所有的评论
	@Select("select id,articleId,userId,content,created from cms_comment where articleId=#{value} order by created desc")
	List<Comment> listCommentByArticleId(int articleId);
}
